package javaNIO1.customerCharset;

import java.nio.charset.Charset;
import java.nio.charset.spi.CharsetProvider;
import java.util.HashSet;
import java.util.Iterator;

/**
 * Created with Intel IDEA.
 * 自定义字符集提供方
 *
 * @Auther: gjt
 * @Date: 2024/8/4 15:24
 */
public class RonsoftCharsetProvider extends CharsetProvider {
    private static final String CHARSET_NAME = "X-ROT13";
    private Charset rot13 = null;

    public RonsoftCharsetProvider() {
        this.rot13 = new Rot13Charset(CHARSET_NAME, new String[0]);
    }

    public Charset charsetForName(String charsetName) {
        if (charsetName.equalsIgnoreCase(CHARSET_NAME)) {
            return rot13;
        }
        return null;
    }

    public Iterator charsets() {
        HashSet hashSet = new HashSet(1);
        hashSet.add(rot13);
        return hashSet.iterator();
    }
}
